﻿using Shows.Data;
using Shows.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ShowsAndCharacters.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            List<Show> shows;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                shows = db.Shows.ToList();
            }
            return View(shows);
        }
[HttpGet]
        public ActionResult AddShow()
        {
           

            return View();
        }
[HttpPost]
        public ActionResult AddShow(string title, string image, string description, Genre genre)
        {
            Show show = new Show();
            show.Title = title;
            show.Image = image;
            show.Description = description;
            show.Genre = genre;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                show = db.Shows.Add(show);
                db.SaveChanges();
            }

            return RedirectToAction("Character/AddCharacter/" + show.Id);
        }
        public ActionResult ShowDetails(int id)
        {
            Show show;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                show = db.Shows.Include("Shows").Where(x => x.Id == id).FirstOrDefault();
            }

            return View(show);
        }
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}